package com.qf.servlet;

import com.qf.pojo.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author AzureSky_X
 * @Date 2021/1/6 9:18
 * @Version 1.0
 * 显示登录用户的名字
 */
@WebServlet("/showname")
public class ShowNameServlet extends HttpServlet {

    @Override
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取并展示登录用户的用户名
        User user= (User) request.getAttribute("user");
        System.out.println("欢迎"+user.getUsername()+"！");
    }

    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}